package com.example.zhongcao.mapper;

import com.example.zhongcao.entity.Zhongcao;
import com.example.zhongcao.utils.UpdateSQLProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ZhongcaoMapper {

    @Insert("insert into zhongcao(title,author,intro,good_num,openid,price,address) values(#{title},#{author},#{intro},#{goodNum},#{openid},#{price},#{address})")
    void insertZhongcao(Zhongcao zc);

    @Select("select * from zhongcao where title=#{title}")
    Zhongcao selectByTitle(String title);

    @Select("select * from zhongcao where openid=#{openid} order by good_num desc")
    List<Zhongcao> selectByGoodNum(String openid);

    @Select("select * from zhongcao order by good_num desc")
    List<Zhongcao> selectByGoodNumAll();

    @Select("select * from zhongcao_withsign where signname like '%${sign}%'")
    List<Zhongcao> selecyBySignAll(String sign);

    @Select("select * from zhongcao where openid=#{openid} order by create_time desc")
    List<Zhongcao> selectByTime(String openid);

    @Select("SELECT * FROM zhongcao WHERE openid=#{openid} and title like '%${keyword}%'")
    List<Zhongcao> selectByKeyword(String openid,String keyword);

    @Select("SELECT * FROM zhongcao WHERE title like '%${keyword}%'")
    List<Zhongcao> selectBykeywordAll(String keyword);

    @Select("select * from zhongcao where id=#{zhongcaoid}")
    Zhongcao selectByZhongcaoid(Integer zhongcaoid);

    @UpdateProvider(type = UpdateSQLProvider.class,method = "getUpdateSql")
    void updateZhongcao(@Param("table") String table,@Param("source") Zhongcao zc,@Param("condition") String condition);
}
